<template>
    <div>
        <table>
            <tr>
                <td>标题</td>
                <td>内容</td>
                <td>图片</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in new_list" :key="i.id">
                <td>{{i.title}}</td>
                <td>{{i.new_content}}</td>
                <td><img :src="url+i.img" alt=""></td>
                <td><input type="button" value="删除"><input type="button" value="评论" @click="comment(i.id)"></td>
            </tr>
        </table>
        <div>
            <button v-for="i in page_list" @click="get_num($event)" :value="i" :key="i.l">{{i}}</button>
        </div>
        
    </div>
</template>


<script>
import axios from 'axios'
export default {
    data(){
        return{
            new_list: [],
            page_list: [],
            p: '1',
            get_id:sessionStorage.getItem('id'),
            url:'http://127.0.0.1:8000'
        }
    },
    methods:{
        get_page(){
            axios({
                url:'http://127.0.0.1:8000/app0e/page/',
                method:'get',
                params:{'page':this.p}
            }).then(res=>{
                console.log(res.data)
                this.cate_list = res.data.new_ser
                this.page_list = res.data.page_list
            })
        },
        get_num(event){
            this.p = event.target.value 
            console.log(this.p)
            this.get_page()  
        },
        comment(id){
            if(get_id){
                this.$router.push({path:'/comment/'+id})
            }
            else{
                this.$router.push({path:'/login/'})
            }
        }
    },
    created(){
        this.get_page()
    }
}
</script>